#include "Grenade.h"
#include "RSManager.h"
#include "Box.h"
#include "Sprite.h"


Grenade::Grenade() : Object(new Box(D3DXVECTOR2(), D3DXVECTOR2(), D3DXVECTOR2()), ObjGrenade), MoveObject()
{	
}


Grenade::~Grenade(void)
{
}

void Grenade::process(ObjectType oType, D3DXVECTOR2 pos, float v)
{
	_isAlive = true;	
	_timeToLive = 0;
	_box->_position = pos;	
	_box->_v.x = _box->_v.y = v;
	_sprite->Reset(0);
	delay = 0;
}

void Grenade::update()
{	
	if(!moveDiagonalThrow())
	{					
		delay += GAME_TIME;
		if(delay >= 150)
		{
			delay = 0;
			_sprite->Next();
			if(_sprite->GetCurrentIndex() == 0)
				_isAlive = false;
		}
	}	
}

void Grenade::render()
{
	_sprite->Render(_box->_position);
}

void Grenade::init()
{
	_sprite = RSManager::getInstance()->getSprite(GRENADE);	
	AssignMove(_box);
	_box->_size = _sprite->getRenderSize();
	delay = 0;
}

bool Grenade::isAlive()
{
	if (!_isAlive)
	{
		if(_timeToLive >= 250)			
			return false;
		_timeToLive += GAME_TIME;
	}
	return true;	
}

